package com.cet.lxf.reflection.test02;

import java.lang.reflect.Field;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-07-29 09:55
 **/
public class Main02 {

    public static void main(String[] args) throws Exception {
        Person02 p = new Person02("Xiao Ming");
        Class c = p.getClass();
        Field f = c.getDeclaredField("name");
        f.setAccessible(true);
//        Object value = f.get(p);
//        System.out.println(value);
        f.set(p, "Xiao Hong");
        System.out.println(p.getName());

    }
}

class Person02 {
    private String name;

    public Person02(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
